package com.yifeng.repo.micro.service.server.engine.core.temp;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 消息发送类型枚举类
 */
@Getter
@AllArgsConstructor
//@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum MsgSendTypeEnum {
    MARKETING(0, "营销"),
    REALTIME(1, "实时"),
    NON_REALTIME(2, "准实时"),
    CALLBACK(3, "回调"),
    DIRECT(4, "直接"),
    ;

    @EnumValue
    @JsonValue
    private final Integer code;
    private final String name;

    private static final Map<Integer, MsgSendTypeEnum> mappings = new HashMap<>(8);

    static {
        for (MsgSendTypeEnum msgChannel : values()) {
            mappings.put(msgChannel.getCode(), msgChannel);
        }
    }

//    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static MsgSendTypeEnum resolve(Integer code) {
        return (code != null ? mappings.get(code) : null);
    }

    public long getDeliveryTimeMillis() {
        switch (this) {
            // 4小时
            case MARKETING:
                return 4 * 60 * 60 * 1000L;
            // 10分钟
            case REALTIME:
                return 10 * 60 * 1000L;
            // 30分钟
            case NON_REALTIME:
                return 30 * 60 * 1000L;
            // 6小时
            case CALLBACK:
                return 6 * 60 * 60 * 1000L;
            default:
                return 0L;
        }
    }
}
